<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">

    <title>徐一炜的个人博客登录</title>
    <meta name="author" content="${config.authorName!}(${config.authorEmail!})">
    <meta name="keywords" content="${config.siteName!}"/>
    <meta name="description" content="${config.siteDesc!}" id="meta_description">
    <link rel="canonical" href="${config.siteUrl!}/about" />
    <link href="${config.siteFavicon!}" rel="shortcut icon" type="image/x-icon">
    <link href="static/css/bootstrap.min.css" rel="stylesheet">
    <link href="static/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="static/css/animate.css" rel="stylesheet">
    <link href="static/css/style.css" rel="stylesheet">
    <link href="static/css/login.css" rel="stylesheet">
    <link href="${ctxPath}/static/css/plugins/validate/bootstrapValidator.min.css" rel="stylesheet">

    <!-- 全局js -->
    <script src="${ctxPath}/static/js/jquery.min.js?v=2.1.4"></script>
    <script src="${ctxPath}/static/js/plugins/validate/bootstrapValidator.min.js"></script>
    <script src="${ctxPath}/static/js/plugins/validate/zh_CN.js"></script>
    <script src="${ctxPath}/static/js/common/ajax-object.js"></script>
    <script src="${ctxPath}/static/js/plugins/layer/layer.js"></script>
    <script type="text/javascript" src="${ctxPath}/static/js/common/Feng.js"></script>
    <script type="text/javascript" src="${ctxPath}/static/js/common/xyw.tool.js"></script>

    <script type="text/javascript" src="${ctxPath}/static/js/plugins/jsencrypt/jsencrypt.min.js"></script>
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <script>
        if (window.top !== window.self) {
            window.top.location = window.location;
        }
    </script>
    <style>
        .layui-layer-content{
            color: black;
        }
    </style>
</head>

<body class="signin">
<div class="signinpanel">
    <div class="row">
        <div class="col-sm-7">
            <div class="signin-info">
                <div class="logopanel m-b">
                    <h1>xblog</h1>
                </div>
                <div class="m-b"></div>
                <h4>欢迎登录 <strong>徐一炜的个人博客</strong></h4>
                <!--<ul class="m-b">-->
                    <!--<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势一</li>-->
                    <!--<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势二</li>-->
                    <!--<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势三</li>-->
                    <!--<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势四</li>-->
                    <!--<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势五</li>-->
                <!--</ul>-->
                <strong>还没有账号？ <a href="${config.siteUrl!}/register">立即注册&raquo;</a></strong>
            </div>
        </div>
        <div class="col-sm-5">
            <form method="post" action="/loginAction"  id="loginInfoForm">
                <h4 class="no-margins">登录：</h4>
                <h4 style="color: red;">${tips!}</h4>
                <input type="text" id="jsenAccount" name="account"  hidden />
                <input type="text" id="jsenPassWord" name="password"  hidden />
                <!--<p class="m-t-md">登录到H+后台主题UI框架</p>-->
                <input type="text" id="account" name="clearAccount"  class="form-control uname" placeholder="用户名" />
                <input type="password"  id="password" name="clearPassword" class="form-control pword m-b" placeholder="密码" />
                <a href="">忘记密码了？</a>
                <button type="button" onclick="login()" class="btn btn-success btn-block" disabled="disabled" id="login-btn">登录</button>
            </form>
        </div>
    </div>
    <div class="signup-footer">
        <div class="pull-left">
            &copy; 2018 All Rights Reserved. xblog
        </div>
    </div>
</div>
</body>
<script>
    var publicKey = null;
    var encrypt = new JSEncrypt();
    $.ajax({
        url: "/api/generateBase64PublicKey",
        type: "post",
        dataType: "json",
        success: function(data) {
            Feng.pass(data,function () {
                if(data.data){
                    publicKey = data.data;
                };
                if(publicKey==null){
                    Feng.error("获取publicKey失败，请联系管理员！");
                    return;
                }else{
                    $("#login-btn").removeAttr("disabled");
                }
            })

        }
    });

    var LoginInfo = {
        validateFields: {
            clearAccount: {
                validators: {
                    notEmpty: {
                        message: '用户名不能为空'
                    }
                }
            },
            clearPassword: {
                validators: {
                    notEmpty: {
                        message: '密码不能为空'
                    }
                }
            }
        }
    };

    Feng.initValidator("loginInfoForm", LoginInfo.validateFields);

    function login() {
        $('#loginInfoForm').data("bootstrapValidator").resetForm();
        $('#loginInfoForm').bootstrapValidator('validate');
        var isValid =  $("#loginInfoForm").data('bootstrapValidator').isValid();
        if(isValid){
            var form = document.getElementById('loginInfoForm');
            encrypt.setPublicKey(publicKey);
            var username = encrypt.encrypt($("#account").val().trim());
            var password = encrypt.encrypt($("#password").val().trim());
            $("#jsenAccount").val(username);
            $("#jsenPassWord").val(password);
            //jquery提交的时候  bootstrap验证会产生success  当form表单有success的时候 则jquery提交的form表单会不成功。 因此只能使用js
            form.submit();
        }
    }

</script>
</html>